package leecode

func combine(n int, k int) (result [][]int) {
	var backtracking func(n, k, startIndex int)
	path := make([]int, 0, k)
	backtracking = func(n, k, startIndex int) {
		if len(path) == k {
			tmp := make([]int, len(path))
			copy(tmp, path)
			result = append(result, tmp)
			return
		}
		for i := startIndex; i <= n; i++ {
			path = append(path, i)
			backtracking(n, k, i+1)
			path = path[:len(path)-1]
		}
	}
	backtracking(n, k, 1)
	return
}
